package com.lwphk.easydocs.core.parameter.parse;

import java.lang.reflect.Parameter;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import com.lwphk.easydocs.core.ParameterParseAbstract;
import com.lwphk.easydocs.core.vo.ContentType;
import com.lwphk.easydocs.core.vo.MethodInfo;
import com.lwphk.easydocs.core.vo.ParamInfo;

public class PrimitiveParameterHandler extends ParameterParseAbstract {

	@Override
	public void parse(Parameter e, MethodInfo mi) throws Exception{
		
		ParamInfo pi = buildBasicInfo(e);

		PathVariable pv = e.getAnnotation(PathVariable.class);
		if (pv != null) {
			pi.setRequire(pv.required());
			mi.getPathParams().add(pi);
		} else {
			RequestBody requestBody = e.getAnnotation(RequestBody.class);
			
			if (requestBody != null) {
				mi.setContentType(ContentType.JSON);
				mi.setBodyVal("");
				pi.setName("");
				pi.setType(e.getType().getSimpleName());
				mi.getBodyParams().add(pi);
			} else {

				mi.getQueryParams().add(pi);

			}
			
		}

	}

}
